package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.facade.PubSysInfoService;
import com.fdb.efp.flow.service.facade.InstFlowEventService;
import com.fdb.efp.flow.service.facade.InstFlowProcessService;
import com.fdb.efp.nls.service.dao.RscAdjustAppDao;
import com.fdb.efp.nls.service.domain.RscAdjustApp;
import com.fdb.efp.nls.service.facade.RscAdjustAppService;
import com.fdb.efp.nls.service.vo.RscAdjustAppVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 风险分类调整申请表				<p>
 * @author ligm
 * @date 2019-09-04
 */
@Service("rscAdjustAppService")
public class RscAdjustAppServiceImpl implements RscAdjustAppService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(RscAdjustAppServiceImpl.class);

	@Autowired
	private RscAdjustAppDao rscAdjustAppDao;

	@Autowired
	@Qualifier("pubSysInfoService")
	private PubSysInfoService pubSysInfoService;
	@Autowired
	@Qualifier("instFlowProcessService")
	private InstFlowProcessService instFlowProcessService;
	@Autowired
	@Qualifier("instFlowEventService")
	private InstFlowEventService instFlowEventService;
	/**
	 * 新增操作
	 */
	public int insertRscAdjustApp(RscAdjustAppVO inRscAdjustAppVo) {
		logger.debug("当前新增数据为:"+ inRscAdjustAppVo.toString());
		int num = 0;
		try {
			RscAdjustApp rscAdjustApp = new RscAdjustApp();
			beanCopy(inRscAdjustAppVo, rscAdjustApp);
			num = rscAdjustAppDao.insertRscAdjustApp(rscAdjustApp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(RscAdjustAppVO inRscAdjustAppVo) {
		logger.debug("当前删除数据条件为:"+ inRscAdjustAppVo);
		int num = 0;
		try {
			RscAdjustApp rscAdjustApp = new RscAdjustApp();
			beanCopy(inRscAdjustAppVo, rscAdjustApp);
			num = rscAdjustAppDao.deleteByPk(rscAdjustApp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscAdjustAppVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(RscAdjustAppVO inRscAdjustAppVo) {
		logger.debug("当前修改数据为:"+ inRscAdjustAppVo.toString());
		int num = 0;
		try {
			RscAdjustApp rscAdjustApp = new RscAdjustApp();
			beanCopy(inRscAdjustAppVo, rscAdjustApp);
			num = rscAdjustAppDao.updateByPk(rscAdjustApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscAdjustAppVo +"修改的数据条数为"+ num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public RscAdjustAppVO queryByPk(RscAdjustAppVO inRscAdjustAppVo) {

		logger.debug("当前查询参数信息为:"+ inRscAdjustAppVo);
		try {
			RscAdjustApp queryRscAdjustApp = new RscAdjustApp();
			beanCopy(inRscAdjustAppVo, queryRscAdjustApp);
			RscAdjustApp queryRslRscAdjustApp = rscAdjustAppDao.queryByPk(queryRscAdjustApp);
			if (Objects.nonNull(queryRslRscAdjustApp)) {
				RscAdjustAppVO outRscAdjustAppVo = beanCopy(queryRslRscAdjustApp, new RscAdjustAppVO());
				logger.debug("当前查询结果为:"+ outRscAdjustAppVo.toString());
				return outRscAdjustAppVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustAppVO> queryAllOwner(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscAdjustAppVO> list = null;
		try {
			List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryAllOwnerByPage(rscAdjustAppVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscAdjustApps.size());
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustAppVO> queryAllCurrOrg(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryAllCurrOrgByPage(rscAdjustAppVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+rscAdjustApps.size());
		List<RscAdjustAppVO> list = null;
		try {
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustAppVO> queryAllCurrDownOrg(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryAllCurrDownOrgByPage(rscAdjustAppVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rscAdjustApps.size());
		List<RscAdjustAppVO> list = null;
		try {
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前产品种类
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustAppVO> queryAllCurrOwnerPrd(RscAdjustAppVO rscAdjustAppVo) {
		logger.debug("当前查询产品种类数据信息的参数信息为:");
		List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryAllCurrOwnerPrdByPage(rscAdjustAppVo);
		logger.debug("当前查询产品种类数据信息的结果集数量为:"+ rscAdjustApps.size());
		List<RscAdjustAppVO> list = null;
		try {
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	public List<RscAdjustAppVO> queryExAllOwner(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscAdjustAppVO> list = null;
		try {
			List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryExAllOwner(rscAdjustAppVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscAdjustApps.size());
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustAppVO> queryExAllCurrOrg(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryExAllCurrOrg(rscAdjustAppVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+rscAdjustApps.size());
		List<RscAdjustAppVO> list = null;
		try {
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustAppVO> queryExAllCurrDownOrg(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryExAllCurrDownOrg(rscAdjustAppVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rscAdjustApps.size());
		List<RscAdjustAppVO> list = null;
		try {
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前产品种类
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustAppVO> queryExAllCurrOwnerPrd(RscAdjustAppVO rscAdjustAppVo) {
		logger.debug("当前查询产品种类数据信息的参数信息为:");
		List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryExAllCurrOwnerPrd(rscAdjustAppVo);
		logger.debug("当前查询产品种类数据信息的结果集数量为:"+ rscAdjustApps.size());
		List<RscAdjustAppVO> list = null;
		try {
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * TODO: 根据借据编号查询分类调整申请表
	 * @author xiezw
	 * @params  * @param null
	 * @return
	 * @date 2019/9/5 10:19
	 * @version 0.1
	 */
	public List<RscAdjustAppVO> queryByBillNo(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryAllByBillNo(rscAdjustAppVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rscAdjustApps.size());
		List<RscAdjustAppVO> list = null;
		try {
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * TODO: 根据分类调整流水号更新调整申请表
	 * @author xiezw
	 * @params  * @param null
	 * @return
	 * @date 2019/9/5 15:26
	 * @version 0.1
	 */
	public int updateByRscAdjNo(RscAdjustAppVO inRscAdjustAppVo) {
		logger.debug("当前修改数据为:"+ inRscAdjustAppVo.toString());
		int num = 0;
		try {
			RscAdjustApp rscAdjustApp = new RscAdjustApp();
			beanCopy(inRscAdjustAppVo, rscAdjustApp);
			num = rscAdjustAppDao.updateByRscAdjNo(rscAdjustApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscAdjustAppVo +"修改的数据条数为"+ num);
		return num;
	}

	/**
	 * TODO: 根据解除分类调整流水号更新调整申请表
	 * @author xiezw
	 * @params  * @param null
	 * @return
	 * @date 2019/9/5 15:26
	 * @version 0.1
	 */
	public int updateByRscRmNo(RscAdjustAppVO inRscAdjustAppVo) {
		logger.debug("当前修改数据为:"+ inRscAdjustAppVo.toString());
		int num = 0;
		try {
			RscAdjustApp rscAdjustApp = new RscAdjustApp();
			beanCopy(inRscAdjustAppVo, rscAdjustApp);
			num = rscAdjustAppDao.updateByRscRmNo(rscAdjustApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscAdjustAppVo +"修改的数据条数为"+ num);
		return num;
	}

	/**
	 * TODO: 根据分类调整流水号删除申请数据
	 * @author xiezw
	 * @params  * @param null
	 * @return
	 * @date 2019/9/5 15:55
	 * @version 0.1
	 */
	public int deleteByRscAdjNo(RscAdjustAppVO inRscAdjustAppVo) {
		logger.debug("当前删除数据条件为:"+ inRscAdjustAppVo);
		int num = 0;
		try {
			RscAdjustApp rscAdjustApp = new RscAdjustApp();
			beanCopy(inRscAdjustAppVo, rscAdjustApp);
			num = rscAdjustAppDao.deleteByRscAdjNo(rscAdjustApp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscAdjustAppVo +"删除的数据条数为"+ num);
		return num;
	}

	/**
	 * TODO: 根据解除分类调整流水号删除申请数据
	 * @author xiezw
	 * @params  * @param null
	 * @return
	 * @date 2019/9/5 15:55
	 * @version 0.1
	 */
	public int deleteByRscRmNo(RscAdjustAppVO inRscAdjustAppVo) {
		logger.debug("当前删除数据条件为:"+ inRscAdjustAppVo);
		int num = 0;
		try {
			RscAdjustApp rscAdjustApp = new RscAdjustApp();
			beanCopy(inRscAdjustAppVo, rscAdjustApp);
			num = rscAdjustAppDao.deleteByRscRmNo(rscAdjustApp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscAdjustAppVo +"删除的数据条数为"+ num);
		return num;
	}

	public List<RscAdjustAppVO> queryAllAppr(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryAllApprByPage(rscAdjustAppVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rscAdjustApps.size());
		List<RscAdjustAppVO> list = null;
		try {
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * TODO: 根据风险分类调整流水号查询表
	 * @author xiezw
	 * @params  * @param null
	 * @return
	 * @date 2019/9/17 15:01
	 * @version 0.1
	 */
	public RscAdjustAppVO queryByAdjNo(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询参数信息为:"+ rscAdjustAppVo);
		try {
			RscAdjustApp queryRslRscAdjustApp = rscAdjustAppDao.queryByRscAdjNo(rscAdjustAppVo);
			if (Objects.nonNull(queryRslRscAdjustApp)) {
				RscAdjustAppVO outRscAdjustAppVo = beanCopy(queryRslRscAdjustApp, new RscAdjustAppVO());
				logger.debug("当前查询结果为:"+ outRscAdjustAppVo.toString());
				return outRscAdjustAppVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;

	}

	/**
	 * TODO: 根据风险分类调整解除流水号查询表
	 * @author xiezw
	 * @params  * @param null
	 * @return
	 * @date 2019/9/17 15:01
	 * @version 0.1
	 */
	public RscAdjustAppVO queryByRmNo(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询参数信息为:"+ rscAdjustAppVo);
		try {
			RscAdjustApp queryRslRscAdjustApp = rscAdjustAppDao.queryByRscRmNo(rscAdjustAppVo);
			if (Objects.nonNull(queryRslRscAdjustApp)) {
				RscAdjustAppVO outRscAdjustAppVo = beanCopy(queryRslRscAdjustApp, new RscAdjustAppVO());
				logger.debug("当前查询结果为:"+ outRscAdjustAppVo.toString());
				return outRscAdjustAppVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;

	}

	/**
	 * 用于导出查询出的所有数据
	 * @author xiezw
	 * @params  * @param null
	 * @return
	 * @date 2019/11/15 9:47
	 * @version 0.1
	 */
	public List<RscAdjustAppVO> queryAllExport(RscAdjustAppVO rscAdjustAppVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscAdjustAppVO> list = null;
		try {
			List<RscAdjustApp> rscAdjustApps = rscAdjustAppDao.queryAll(rscAdjustAppVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscAdjustApps.size());
			pageSet(rscAdjustApps, rscAdjustAppVo);
			list = (List<RscAdjustAppVO>) beansCopy(rscAdjustApps, RscAdjustAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}
}
